package com.maysham.coder.server.controller;

import com.maysham.coder.server.common.Response;
import com.maysham.coder.server.config.auth.SecurityUtil;
import com.maysham.coder.server.model.Group;
import com.maysham.coder.server.service.GroupService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(value = "/api/group", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class GroupController {
    @Resource
    private GroupService groupService;

    @GetMapping(value = "/list")
    public Response<List<Group>> queryGroup() {
        return Response.ok(groupService.queryUserGroups(SecurityUtil.current().getId()));
    }

    @PostMapping("/create")
    public Response<Group> create(@RequestBody @Valid Group group) {
        return Response.ok(groupService.create(group));
    }
}
